package linechart;

import common.ChartDemo;
import common.ChartUtil;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.Dataset;

import javax.swing.*;
import java.awt.*;

public class LineChart3DDemo1 extends ChartDemo {

    public LineChart3DDemo1(String title) {
        super(title);
    }

    @Override
    protected Dataset createDataset() {
        DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset();
        defaultCategoryDataset.addValue(143.19999999999999D, "S1", "C1");
        defaultCategoryDataset.addValue(120.2D, "S1", "C2");
        defaultCategoryDataset.addValue(135D, "S1", "C3");
        defaultCategoryDataset.addValue(115D, "S1", "C4");
        defaultCategoryDataset.addValue(98.700000000000003D, "S2", "C1");
        defaultCategoryDataset.addValue(63.200000000000003D, "S2", "C2");
        defaultCategoryDataset.addValue(71.400000000000006D, "S2", "C3");
        defaultCategoryDataset.addValue(55D, "S2", "C4");
        return defaultCategoryDataset;
    }

    @Override
    protected JFreeChart createChart(Dataset dataset) {
        if (!(dataset instanceof CategoryDataset)) {
            return null;
        }
        CategoryDataset categoryDataset = (CategoryDataset)dataset;
        JFreeChart jFreeChart = ChartFactory.createLineChart("Line Chart Demo 1", null,
                "Class Count", categoryDataset, PlotOrientation.VERTICAL,
                false, true, false);
        CategoryPlot plot = (CategoryPlot) jFreeChart.getPlot();
        NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
        numberAxis.setAutoRangeIncludesZero(false);
        numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        return jFreeChart;
    }

    public static void main(String[] args) {
        LineChart3DDemo1 demo1 = new LineChart3DDemo1("LineChart3DDemo1");
        ChartUtil.showChartDemo(demo1);
    }
}
